package com.jason.basicandroid.ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.ToggleButton;

public class ButtonControl extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    public void onBasicBtnClick(View srcBtn) {
    	switch(srcBtn.getId()) {
    	case R.id.basicBtn:
    		Button basicBtn = (Button)srcBtn;
    		basicBtn.setText("Basic Button (Ever Pressed)");
    		break;
    	}
    }
    
    public void onToggleBtnClick(View srcBtn) {
    	switch(srcBtn.getId()) {
    	case R.id.tglBtn:
    		ToggleButton tglBtn = (ToggleButton)srcBtn;
    		TextView tv = (TextView)findViewById(R.id.tvTglBtnValue);
    		String str = "\tToggle Button's Value: ";
    		
    		if(tglBtn.isChecked()) {
    			str += "Checked";
    		} else {
    			str += "Unhecked";
    		}
    		
    		tv.setText(str);
    		
    		break;
    	}
    }
    
    public void onCheckBoxClick(View srcBtn) {
    	switch(srcBtn.getId()) {
    	case R.id.chkChicken:
    	case R.id.chkFish:
    		CheckBox chkChicken = (CheckBox)findViewById(R.id.chkChicken);
    		CheckBox chkFish = (CheckBox)findViewById(R.id.chkFish);
    		TextView tv = (TextView)findViewById(R.id.tvChkValue);
    		String str = "\tWhat you select:";
    		
    		if(chkChicken.isChecked()) {
    			str += " Chicken";
    		}
    		if(chkFish.isChecked()) {
    			str += " Fish";
    		}
    		
    		tv.setText(str);
    		
    		break;
    	}
    }
    
    public void onRadioBtnClick(View srcBtn) {
    	switch(srcBtn.getId()) {
    	case R.id.rdChicken:
    	case R.id.rdFish:
    		RadioButton rdChicken = (RadioButton)findViewById(R.id.rdChicken);
    		RadioButton rdFish = (RadioButton)findViewById(R.id.rdFish);
    		TextView tv = (TextView)findViewById(R.id.tvRadioValue);
    		String str = "\tWhat you select:";
    		
    		if(rdChicken.isChecked()) {
    			str += " Chicken";
    		}
    		if(rdFish.isChecked()) {
    			str += " Fish";
    		}
    		
    		tv.setText(str);
    		
    		break;
    	}
    }
}